package com.ktjiaoyu.crm.controller;

import com.ktjiaoyu.crm.pojo.User;
import com.ktjiaoyu.crm.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName : ExampleController
 * @Description :
 * @Author : Lzz
 * @Date: 2023/11/20 09:00:01
 */
@Controller
public class ExampleController {

    @Resource
    UserService userService;

    @RequestMapping(value = "/index")
    public String index(){

        return "demo/layout/index";
    }

    @RequestMapping(value = "/fragment")
    public String fragment(){

        return "demo/layout/fragment";
    }

    @RequestMapping(value = "/content")
    public String content(){

        return "demo/layout/content";
    }

    @GetMapping("/hello/{id}")
    public String getUser(@PathVariable("id") Long id, Model model){
        User user = userService.getById(id);
        model.addAttribute("user",user);
        model.addAttribute("str","hello world!");
        List<User> users = userService.list();
        model.addAttribute("users",users);
        //map.put("user", user);
        return "demo/hello";
    }

    @GetMapping("/toTest")
    public String toTest(){

        return "demo/test";
    }

}
